using System;
using System.Collections.Generic;
using System.Text;
using NBusiness.Query;

namespace NBusiness.MySql.Query
{
    public class MySqlFunction : ISelectable, IEvaluatable 
    {
        #region Member properties and fields
		private string _name;

        public string Name
        {
            get { return _name; }
            set { _name = value; }
        }

        private List<IEvaluatable> _parameters = new List<IEvaluatable>();
        public List<IEvaluatable> Parameters
        {
            get { return _parameters; }
        } 
	    #endregion

        public MySqlFunction() { }
        public MySqlFunction(string name, params IEvaluatable[] parameters)
        {
            _name = name;
            _parameters.AddRange(parameters);
        }

        #region IRelationalElement Members

        public string ToSql()
        {
            StringBuilder sb = new StringBuilder(_name);
            sb.Append("(");
            for (int x = 0; x < _parameters.Count; x++)
            {
                if (x > 0) sb.Append(", ");
                sb.Append(Parameters[x].ToSql());
            }
            sb.Append(")");

            return sb.ToString();
        }

        private IRelationalElement _parent;
        public IRelationalElement Parent
        {
            get { return _parent; }
            set { _parent = value; }
        }

        #endregion
    }
}
